﻿

//获取当前路径
function getCurrentDirectory() {
    var locHref = location.href;
    var addr = locHref.substring(0, locHref.lastIndexOf("/") + 1);
    return addr;
    alert(addr);
    var locArray = locHref.split("/");
    delete locArray[locArray.length - 1];
    var dirTxt = locArray.join("//");
    alert(locArray);
    var temp = dirTxt.substring(11);
    alert(temp);
    var newtemp = "";
    //需要过滤空格%20 UNICODE显示
    var i;
    for (i = 0; i < temp.length; i++) {
        if (temp.substr(i, 3) == "%20") {
            newtemp = newtemp + " ";
            i = i + 2;
        } else {
            newtemp = newtemp + temp.substr(i, 1);
        }
    }
    alert(newtemp);
    return newtemp;
}

var varSuccess = "成功";
var varFailed  = "失败";

var varGetTz   = "请先获取指纹特征";
var varGetMb   = "请先获取指纹模板";

var varNoEmpty = "客户信息不能为空";	
var varMax32   = "客户信息应不大于32";	
	
var varOpenDeviceFailed = "打开设备失败";
var varCancel           = "取消";
var varTimeout          = "超时"
var varReadImageFailed  = "采集失败";
var varUpImageFailed    = "上传失败";
var varGetTzFailed      = "提取特征失败";
var varGetMbFailed      = "合并模板失败";
var varParameterIllegal = "参数非法";     
var varIsGettingImage   = "已经在采集图像";  

function IsSuccess(tmp)
{
		if(tmp=="-1")
    {
    	alert(varOpenDeviceFailed);
    	return -1;
    }
    else if(tmp=="-2")
    {
    	alert(varCancel);
    	return -2;
    }
    else if(tmp=="-3")
    {
    	alert(varTimeout);
    	return -3;
    }
    else if(tmp=="-4")
    {
    	alert(varReadImageFailed);
    	return -4;
    }
    else if(tmp=="-5")
    {
    	alert(varUpImageFailed);
    	return -5;
    }
    else if(tmp=="-6")
    {
    	alert(varGetTzFailed);
    	return -6;
    }
    else if(tmp=="-7")
    {
    	alert(varGetMbFailed);
    	return -7;
    }
     else if(tmp=="-10")
    {
    	alert(varParameterIllegal);
    	return -10;
    }
    else if(tmp=="-11")
    {
    	alert(varIsGettingImage);
    	return -11;
    }	
    else
    {
    	return 0;
    }	
}


function Button_GetImage(onSuccess, onError) {
    //    document.getElementById("img1").src = "/images/miaxis.jpg";
    //    document.getElementById("img2").src = "/images/miaxis.jpg";
    //    document.getElementById("img3").src = "/images/miaxis.jpg";
    //    document.getElementById("showtext").value = "";

    var iDevIndex = document.getElementById("devNo").selectedIndex;
    if (iDevIndex == 0) {
        var img1 = fpDevObj.GetImage(iDevIndex, dwWaitTime);
        if (IsSuccess(img1) == 0) {
            onSuccess(img1);
            //document.getElementById(dataHidden).value = img1
            //            var curPath = getCurrentDirectory();
            //            fpDevObj.ImageToBmpFile(curPath + "Img.bmp", img1);
            //            document.getElementById("img1").src = curPath + "Img.bmp"
        } else {
            if (onError) {
                onError();
            }
        }
    }
    else {
        alert("串口不支持采集图像");
    }
}

var tz = 0;
var mb = 0;
function Button_GetMb() {
    document.getElementById("img1").src = "/images/miaxis.jpg";
    document.getElementById("img2").src = "/images/miaxis.jpg";
    document.getElementById("img3").src = "/images/miaxis.jpg";
	document.getElementById("showtext").value ="";
	var iDevIndex = document.getElementById("devNo").selectedIndex;
	if(iDevIndex == 0)
	{
			mb  = fpDevObj.GetTemplate(iDevIndex,dwWaitTime);
			if(IsSuccess(mb) == 0)
			{
				var curPath = getCurrentDirectory();
				var mbImg1 =	fpDevObj.GetTemplateImage(1);
				fpDevObj.ImageToBmpFile(curPath+"ImgMb1.bmp",mbImg1);
				document.getElementById("img1").src =curPath+"ImgMb1.bmp";
			   		
				var mbImg2 =	fpDevObj.GetTemplateImage(2);
				fpDevObj.ImageToBmpFile(curPath+"ImgMb2.bmp",mbImg2);
				document.getElementById("img2").src =curPath+"ImgMb2.bmp";
			   		
				var mbImg3 =	fpDevObj.GetTemplateImage(3);
				fpDevObj.ImageToBmpFile(curPath+"ImgMb3.bmp",mbImg3);
				document.getElementById("img3").src =curPath+"ImgMb3.bmp";
			   		
				document.getElementById("showtext").value =mb 
			}
	}
	else
	{
		mb  = fpDevObj.GetComTemplate(iDevIndex,dwWaitTime);	
		if(IsSuccess(mb) == 0)
		{
			document.getElementById("showtext").value =mb;
		} 
	} 
}

function Button_GetTz() {
    document.getElementById("img1").src = "/images/miaxis.jpg";
    document.getElementById("img2").src = "/images/miaxis.jpg";
    document.getElementById("img3").src = "/images/miaxis.jpg";
	document.getElementById("showtext").value ="";
	var iDevIndex = document.getElementById("devNo").selectedIndex;
	if(iDevIndex == 0)
	{
			tz  = fpDevObj.GetFeature(iDevIndex,dwWaitTime);
			if(IsSuccess(tz) == 0)
			{
				var curPath = getCurrentDirectory();
				var tzImg =	fpDevObj.GetFeatureImage();
				fpDevObj.ImageToBmpFile(curPath+"ImgTz.bmp",tzImg);
				document.getElementById("img1").src =curPath+"ImgTz.bmp";
				document.getElementById("showtext").value =tz
			} 
	}
	else
	{
			tz  = fpDevObj.GetComFeature(iDevIndex,dwWaitTime);
			if(IsSuccess(tz) == 0)
			{
				document.getElementById("showtext").value =tz
			} 
	} 
}

function Button_Match() {
	  if(tz==0)
	  {
	  	alert(varGetTz);
	  	return;
	  }
	  if(mb==0)
	  {
	  	alert(varGetMb);
	  	return;
	  }
    var ret = fpDevObj.FingerMatch(mb,tz,3);
    if(ret == 0)
    	alert(varSuccess);
    else
    	alert(ret);
}

function Button_GetDevVer() {
		var ret;
		var iDevIndex = document.getElementById("devNo").selectedIndex;
		if(iDevIndex == 0)
		{
   		ret = fpDevObj.GetDevVersion(iDevIndex);
  	}
  	else
  	{
  	 	ret = fpDevObj.GetComDevVersion(iDevIndex);
  	}
    alert(ret);
}

function Button_GetOcxVer() {
		var ret;
   	ret = fpDevObj.GetOcxVersion();
    alert(ret);
}

function Button_GetAlgVer() {
		var ret;
   	ret = fpDevObj.GetAlgVersion();
    alert(ret);
}

